<?php

namespace App\Admin\Metrics\Home;

use App\Models\User;
use App\Services\Tenancy\TenancyService;
use Dcat\Admin\Widgets\Metrics\Card;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;

class TotalUsers extends Card
{
    /**
     * 卡片底部内容.
     *
     * @var string|Renderable|\Closure
     */
    protected $footer;

    /**
     * 初始化卡片.
     */
    protected function init()
    {
        parent::init();
        $this->title('<span style="color:#487BFF;">总用户</span>');
    }

    public function style(string $style)
    {
        return parent::style($style); // TODO: Change the autogenerated stub
    }

    /**
     * 处理请求.
     *
     * @param Request $request
     *
     * @return void
     */
    public function handle(Request $request)
    {
        $this->content(User::query()->count());
//        $this->up(15);
    }

    /**
     * @param int $percent
     *
     * @return $this
     */
    public function up($percent)
    {
        return $this->footer(
            "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
        );
    }

    /**
     * @param int $percent
     *
     * @return $this
     */
    public function down($percent)
    {
        return $this->footer(
            "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
        );
    }

    /**
     * 设置卡片底部内容.
     *
     * @param string|Renderable|\Closure $footer
     *
     * @return $this
     */
    public function footer($footer)
    {
        $this->footer = $footer;

        return $this;
    }

    public function setUpChartMargin()
    {
        parent::setUpChartMargin(); // TODO: Change the autogenerated stub
//        $this->chart->style("background: linear-gradient(180deg, #DFEEFF 0%, #FFF 100%);");
    }

    /**
     * 渲染卡片内容.
     *
     * @return string
     */
    public function renderContent()
    {
//        $this->chart->style("");
        $this->appendHtmlAttribute('style', "background: linear-gradient(180deg, #DFEEFF 0%, #FFF 100%);");
        $content = parent::renderContent();
        $src = asset('static/images/admin/home/to-user.png');
        return <<<HTML
<div class="row" style="margin-bottom: 20px;">
<div class="col-sm-6 d-flex justify-content-between align-items-center mt-1" >
    <p class="ml-1 " style="font-size: 50px">{$content}<span style="font-size: 12px"> (人)</span></p>
</div>
<div class="col-sm-6">
<img src="{$src}" alt="" style="width:90px">
</div>
</div>

HTML;
    }

    /**
     * 渲染卡片底部内容.
     *
     * @return string
     */
    public function renderFooter()
    {
        return $this->toString($this->footer);
    }
}
